<template>
    <el-card class="box-card" :style="{'line-height':enableSwap?'':'25px'}">
        <div slot="header" class="clearfix">
            <span>通用配置</span>
        </div>
        <div>
            <el-row>
                <el-checkbox v-model="autoStart" change="setAutoStart()">
                    开机启动
                </el-checkbox>
            </el-row>
            <el-row style="height: 10px"></el-row>
            <el-row>
                <el-checkbox v-model="messageNotify">消息通知</el-checkbox>
            </el-row>
        </div>
    </el-card>
</template>

<script>
    import { ipcRenderer } from "electron";
    export default {
        created() {
        },
        mounted(){
            this.getSetInfo();
        },
        data() {
            return {
                enableSwap: true,
                autoStart: false,
                messageNotify: true
            }
        },
        methods: {
            changeAutoStart() {
                if (this.autoStart) {
                    this.enableAutoStart()
                } else {
                    this.disableAutoStart()
                }
            },
            enableAutoStart() {
                // 设置自动启动
                ipcRenderer.send('openAutoStart')
            },
            disableAutoStart() {
                // 取消自动启动
                ipcRenderer.send('closeAutoStart')
            },
            getSetInfo() {
                ipcRenderer.invoke("getAutoStartValue").then(res => {
                    this.autoStart = res;
                    this.$watch('autoStart', this.changeAutoStart)
                });
            },
            setAutoStart() {
                ipcRenderer.on("getAutoStartValue").then(res => {
                    this.autoStart = res;
                });
            }
        }
    }
</script>
